﻿using Microsoft.AspNetCore.Mvc;
using TXTD.Admin.Data.Entitys.System;
using TXTD.Admin.Interface.System;
using TXTD.Admin.Model.Core;
using TXTD.Admin.ScheduledTask;

namespace TXTD.Admin.WebApi.Modules.System
{
    [ApiController]
    [Route("api/System/[controller]")]
    public class SysScheduledTaskController : ControllerBase
    {
        private ISysScheduledTaskService service;
        private ScheduledTaskService scheduledTaskService;
        public SysScheduledTaskController(ISysScheduledTaskService _service, ScheduledTaskService scheduledTaskService)
        {
            service = _service;
            this.scheduledTaskService = scheduledTaskService;
        }
        /// <summary>
        /// 获取分页数据
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetPageList")]
        public ResultModel GetPageList([FromQuery] SysScheduledTask model)
        {
            return ResultModel.ResultBy(service.GetPageList(model));
        }
        /// <summary>
        /// 修改状态
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost("UpdateEnabled")]
        public async Task<ResultModel> UpdateEnabled(SysScheduledTask model)
        {
            return ResultModel.ResultByCount(await scheduledTaskService.UpdateTaskEnabled(model));
        }
        /// <summary>
        /// 修改状态
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost("Update")]
        public async Task<ResultModel> Update(SysScheduledTask model)
        {
            return ResultModel.ResultByCount(await scheduledTaskService.UpdateTask(model));
        }
        /// <summary>
        /// 立即执行
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost("ExecuteNow")]
        public async Task<ResultModel> ExecuteNow(SysScheduledTask model)
        {
            return ResultModel.ResultByCount(await scheduledTaskService.ExecuteNow(model));
        }
    }
}
